package org.se.scut.hibernate.dao.model;


import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="tb_userinfo")
public class UserInfo extends Model {

	@Id
	private Integer id;
	
	@Column(name="signature")
	private String signature;
	
	@Column(name="address")
	private String addrres;

	@Column(name = "birthday")
	@Temporal(TemporalType.DATE)
	private Date birthday;
	
	@OneToOne
	@PrimaryKeyJoinColumn
	private LoginInfo loginInfo;
	
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "attention_id")
	private Set<UserInfo> attentions;
	
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "attentioned_id")
	private Set<UserInfo> attentioneds;
	
	@OneToMany(mappedBy = "creator", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<Ablum> ablums;
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@JoinTable(name = "tb_user_ablum", joinColumns = @JoinColumn(name = "user_id", 
	referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "ablum_id",
	referencedColumnName = "id"))
	private Set<Ablum> ablumsOfLoved;
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@JoinTable(name = "tb_user_picture", joinColumns = @JoinColumn(name = "user_id", 
	referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "picture_id",
	referencedColumnName = "id"))
	private Set<Picture> collecteds;
	
	@OneToMany(mappedBy = "creator",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private Set<Picture> uploadeds;

	public String getAddrres() {
		return addrres;
	}

	public void setAddrres(String addrres) {
		this.addrres = addrres;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public Set<UserInfo> getAttentions() {
		return attentions;
	}

	public void setAttentions(Set<UserInfo> attentions) {
		this.attentions = attentions;
	}

	public Set<Ablum> getAblums() {
		return ablums;
	}

	public void setAblums(Set<Ablum> ablums) {
		this.ablums = ablums;
	}

	public Set<Picture> getCollecteds() {
		return collecteds;
	}

	public void setCollecteds(Set<Picture> collecteds) {
		this.collecteds = collecteds;
	}

	public Set<Picture> getUploadeds() {
		return uploadeds;
	}

	public void setUploadeds(Set<Picture> uploadeds) {
		this.uploadeds = uploadeds;
	}

	public Set<UserInfo> getAttentioneds() {
		return attentioneds;
	}

	public void setAttentioneds(Set<UserInfo> attentioneds) {
		this.attentioneds = attentioneds;
	}

	public LoginInfo getLoginInfo() {
		return loginInfo;
	}

	public void setLoginInfo(LoginInfo loginInfo) {
		this.loginInfo = loginInfo;
	}

	public Set<Ablum> getAblumsOfLoved() {
		return ablumsOfLoved;
	}

	public void setAblumsOfLoved(Set<Ablum> ablumsOfLoved) {
		this.ablumsOfLoved = ablumsOfLoved;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
}
